package com.taiyuan.zfmvp.sharding.controller;

import com.taiyuan.zfmvp.sharding.model.TestCode;
import com.taiyuan.zfmvp.sharding.model.TestSharding;
import com.taiyuan.zfmvp.sharding.service.TestShardingService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @param
 * @Author: zhoufang@si-tech.com.cn
 * @Descriiption:
 * @Date 2022/1/30
 * @return
 */
@Controller
@RequestMapping("/add")
public class TestShardingController {

    @Resource
    private TestShardingService testShardingService;

    /**
     * @Author zhoufang@si-tech.com.cn
     * @Description   添加信息
     * @Date 2022/1/30
     * @Param
     * @Return
     */
    @PostMapping("/addInfo")
    @ResponseBody
    public String addInfo(@RequestBody Map<String, Object> inMap) {

        try {
            TestSharding testSharding = new TestSharding();
            testSharding.setCouponCode(inMap.get("couponCode") + "");
            testSharding.setPhoneNo(inMap.get("phoneNo") + "");
            testSharding.setSex((Integer)inMap.get("sex"));
            testShardingService.addShardingInfo(testSharding);
            return "000000";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "000000";
    }


    /**
     * @Author zhoufang@si-tech.com.cn
     * @Description   添加信息
     * @Date 2022/1/30
     * @Param
     * @Return
     */
    @PostMapping("/addCode")
    @ResponseBody
    public String addCode(@RequestBody Map<String, Object> inMap) {

        try {
            TestCode testCode = new TestCode();
            testCode.setCouponCode(inMap.get("couponCode") + "");
            testCode.setPhoneNo(inMap.get("phoneNo") + "");
            testShardingService.addCode(testCode);
            return "000000";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "000000";
    }


    /**
     * @Author zhoufang@si-tech.com.cn
     * @Description
     * @Date 2022/2/2
     * @Param
     * @Return
     */
    @PostMapping("/getById")
    @ResponseBody

    public TestCode getById(@RequestBody Map<String, Object> inMap) {

        try {
            TestCode testCode = testShardingService.getTestCode((Integer)inMap.get("id"));
            int a = testCode.getHigh().intValue();
            if(1 == a ){
                System.out.println("11");

            }
            return testCode;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
